﻿using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model;
using HZ.Supervise.IBLL;
using System.Collections.Generic;
using HZ.Supervise.Model.Enum;
using System.Text;
using System.Text.RegularExpressions;


namespace HZ.Supervise.Web.Company
{
    public partial class CompanyInfo_SCBy23J : BasePage
    {

        public CompanyInfo_SCBy23J()
        {
            this.ModuleNo = Module.生产企业汇总统计.ToString();
            this.PageOperateType = OperateType.非基层医疗机构.ToString();
        }
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                this.AreaControl1.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;
                BindData();
            }
        }

        void QueryControl1_OnQueryClick(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;

        }

        private SuperviseQuery QueryBy()
        {
            SuperviseQuery vs = new SuperviseQuery();

            #region 查询方法



            //System.Text.StringBuilder sb = new System.Text.StringBuilder();

            if (cbProductNameLike.Checked == true)
            {

                vs.Flag = "1";
            }
            else
            {
                vs.Flag = "0";
            }

            if (HZ.Common.zhHansUtil.HaveChineseCode(txtProductName.Text.Trim()) == true)
            {
                vs.ProductName = this.txtProductName.Text.Trim();
            }
            else
            {
                vs.PinyinCode = this.txtProductName.Text.Trim();

            }
            
          

            string timeFrom = string.Intern(this.txtTimeFrom.Text.Trim());

            string timeTo = string.Intern(this.txtTimeTo.Text.Trim());

            if (!string.IsNullOrEmpty(timeFrom))
            {
                vs.CenSubmiitTimeFrom = Convert.ToDateTime(timeFrom);

            }

            if (!string.IsNullOrEmpty(timeTo))
            {
                vs.CenSubmiitTimeTo = Convert.ToDateTime(timeTo);
            }

            if (!string.IsNullOrEmpty(this.txtMedicineModel.Text.Trim()))
            {
                vs.MedicineModelName = txtMedicineModel.Text.Trim();
            }
            if (!string.IsNullOrEmpty(this.txtPack.Text.Trim()))
            {
                vs.Pack = txtPack.Text.Trim();
            }
            if (!string.IsNullOrEmpty(this.txtUnit.Text.Trim()))
            {
                vs.Unit = txtUnit.Text.Trim();

            }
            if (!string.IsNullOrEmpty(this.txtHospitalName.Text.Trim()))
            {
                vs.HospitalName = txtHospitalName.Text.Trim();
            }
            string areaid = AreaControl1.SelectedAreaID;
            if (!string.IsNullOrEmpty(areaid) && areaid != "510000")
            {
                vs.AreaID = areaid;

            }
            else
            {
                vs.AreaID = "22";

            }


            vs.Levels =  "'3','4','5','6'";

           
            if (!string.IsNullOrEmpty(txtAmountFrom.Text.Trim()))
            {
                vs.WarehouseAmountFrom =Convert.ToDecimal( txtAmountFrom.Text.Trim());
                

            }
            if (!string.IsNullOrEmpty(txtAmountTo.Text.Trim()))
            {
                vs.WarehouseAmountTo = Convert.ToDecimal(txtAmountTo.Text.Trim());

                
            }
            vs.Append = this.OrderFileds.SelectedValue + "  " + this.OrderType.SelectedValue;
            return vs;
            #endregion
        }
        private void BindData()
        {
            HZ.Supervise.IBLL.IExecuteContext ie = HZ.Supervise.BLLFactory.ExecuteContext();

            //string orderby = this.OrderFileds.SelectedValue + "  " + this.OrderType.SelectedValue;//排序字段与方式
            int t = 0;
            System.Data.DataTable dt = ie.CompanySC_InfoByType( QueryBy(),  this.AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out t);

            AspNetPager1.RecordCount = t;
            gvwInfo.PageSize = AspNetPager1.PageSize;
            this.gvwInfo.DataSource = dt;
            //HZ.Supervise.Web.Function.ChangeRate(dt, "WareHouseRate");
            //HZ.Supervise.Web.Function.ChangeRate_PS(dt, "DistributeRate");
            //HZ.Supervise.Web.Function.ChangeRate_Sell(dt, "SellRate");
            this.gvwInfo.DataBind();


            //this.lblCount.Text = "采购总金额为：" + PurchaseAmountTotal.ToString() + ";" + "入库总金额：" + WareHouseAmountTotal.ToString() + ";" + "销售总金额：" + SellAmountTotal + ";";

        }


        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
        }

        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            //ViewState["query"] = QueryControl1.UpdateQueryFromValue((SuperviseQuery)ViewState["query"]);
            BindData();
            //GetCompany_SCCount();
        }


        /// <summary>
        /// 跳转至其它页面，同时将本页面的一些参数传至下一页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvwInfo_RowCommand(object sender, GridViewCommandEventArgs e)
        {

        }

        protected void ddlOther_SelectedIndexChanged(object sender, EventArgs e)
        {
            string stkey = "";
            string sessionid = string.Empty;
            GridViewRow row = (GridViewRow)((Control)sender).Parent.Parent;
            DropDownList ddl = (DropDownList)row.FindControl("ddlOther");
            stkey = ddl.SelectedValue;
            if (stkey != "")
            {
                sessionid = Guid.NewGuid().ToString();
                SuperviseQuery query = (SuperviseQuery)ViewState["query"];
                //赋予当前行的主键值
                //query.CompanyName_SC = row.Cells[1].Text; //((LinkButton)row.FindControl("lbnHos")).CommandArgument;
                query.CompanyName_SC = gvwInfo.DataKeys[row.RowIndex].Value.ToString();
                query._QueryPrompt = query._QueryPrompt + " " + gvwInfo.DataKeys[row.RowIndex].Value.ToString();

                Session[sessionid] = query;
                string url = System.Configuration.ConfigurationManager.AppSettings[stkey];
                Response.Redirect(string.Format("{0}?sessionid={1}", url, sessionid));
            }
        }


        protected void btnExport_Click(object sender, EventArgs e)
        {
            HZ.Supervise.IBLL.IExecuteContext ie = HZ.Supervise.BLLFactory.ExecuteContext();

         
            string orderby = this.OrderFileds.SelectedValue + "  " + this.OrderType.SelectedValue;//排序字段与方式
            int t = 0;
            System.Data.DataTable dt = ie.CompanySC_InfoByType(QueryBy(),   1, 0, out t);

            ExportFile.Instance.ExportData(dt, gvwInfo, this.Page);
        }
        protected void lbtnSee_Click(object sender, EventArgs e)
        {
            if (this.lbtnSee.Text == "显示图表")
            {
                ChartControl1.Visible = true;
                this.lbtnSee.Text = "隐藏图表";
            }
            else
            {
                ChartControl1.Visible = false;
                this.lbtnSee.Text = "显示图表";
            }
        }
    }
   
}
